home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Demos / Stars4.s < prev    next >
Encoding:
Text File  |  1997-12-16  |  7.9 KB  |  287 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      3D StarField 4
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demo of a triple buffered starfield.  I didn't orginally write
  7. ;this starfield code, but it was very old so it needed a fair bit of
  8. ;cleaning up to work with the library.  It now runs in 4 colours for a
  9. ;little more depth too...
  10.  
  11.     INCDIR    "INCLUDES:"
  12.     INCLUDE    "dpkernel/dpkernel.i
  13.  
  14. NSTARS    =    800                     ;Number of stars
  15.  
  16. XSPEED    =    -4
  17. YSPEED    =    6
  18. ZSPEED    =    2
  19.  
  20. SCRWIDTH  =    320
  21. SCRHEIGHT =    256
  22.  
  23.     SECTION    "Stars",CODE
  24.  
  25. ;==========================================================================;
  26. ;                             INITIALISE DEMO
  27. ;==========================================================================;
  28.  
  29.     STARTDPK
  30.  
  31. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  32.     move.l    DPKBase(pc),a6
  33.     lea    ScreenTags(pc),a0
  34.     sub.l    a1,a1
  35.     CALL    Init
  36.     tst.l    d0
  37.     beq.s    .Exit
  38.  
  39.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  40.     CALL    Get
  41.     move.l    d0,JoyData
  42.     beq.s    .Exit
  43.     move.l    d0,a0    ;Initialise the joydata structure.
  44.     sub.l    a1,a1
  45.     CALL    Init
  46.     tst.l    d0
  47.     beq.s    .Exit
  48.  
  49.     move.l    Screen(pc),a0
  50.     CALL    Display
  51.  
  52.     bsr.s    Main
  53.  
  54. .Exit    move.l    DPKBase(pc),a6
  55.     move.l    JoyData(pc),a0
  56.     CALL    Free
  57.     move.l    Screen(pc),a0
  58.     CALL    Free
  59.     MOVEM.L    (SP)+,A0-A6/D1-D7
  60.     moveq    #ERR_OK,d0
  61.     rts
  62.  
  63. ;==========================================================================;
  64. ;                                 INITIALISE
  65. ;==========================================================================;
  66.  
  67.     ;Randomize star coordinates
  68.  
  69. Main:    lea    StarCoords,a0            ;a0 = Ptr to star co-ordinates.
  70.     move.w    #NSTARS-1,d7
  71.     move.l    DPKBase(pc),a6
  72. .loop1    move.w    #8192,d1
  73.     CALL    SlowRandom
  74.     move.w    d0,(a0)+
  75.     CALL    SlowRandom
  76.     move.w    d0,(a0)+
  77.     CALL    SlowRandom
  78.     move.w    d0,(a0)+
  79.     dbra    d7,.loop1
  80.  
  81.     ;Construct perspective table
  82.  
  83.     lea    PersTable,a0             ;a0 = ptr to perspective table.
  84.     moveq    #0,d1                    ;d1 = Starting at 0.
  85. .loop2    move.l    #$95FFFF,d2              ;d2 = $95FFFF
  86.     move.l    d1,d3                    ;d3 = d1
  87.     add.w    #300,d3                  ;d3 = ++300
  88.     divu    d3,d2                    ;d2 = ($95ffff)/d3
  89.     move.w    d2,(a0)+                 ;a0 = d2+
  90.     addq.w    #1,d1                    ;d1 = ++1
  91.     cmp.w    #8192,d1                 ;d1 = Equal to 8192?
  92.     bne.s    .loop2
  93.  
  94.     ;Construct plot tables for fast drawing.
  95.  
  96.     lea    PlotXTable,a0            ;a0 = X table - byte positions.
  97.     lea    PlotBTable,a1            ;a1 = Bit table (X related).
  98.     lea    PlotYTable,a2            ;a2 = Y table - line position.
  99.     moveq    #0,d0                    ;d0 = 00
  100. .loop3    move.w    d0,d1                    ;d1 = d0
  101.     lsr.w    #3,d1                    ;d1 = (d0)<<3
  102.     move.w    d1,(a0)+                 ;a0 = d1+
  103.  
  104.     move.w    d0,d1                    ;d1 = d0
  105.     eor.w    #$FFFF,d1                ;d1 = (d0) eor $ffff
  106.     and.w    #%00000111,d1            ;d1 = &%00000111
  107.     move.w    d1,(a1)+                 ;a1 = BitSet++
  108.  
  109.     cmp.w    #SCRHEIGHT,d0    ;Write out the Y values for the
  110.     bge.s    .plot2    ;table.
  111.     move.w    d0,d1    ;d1 = Line Number.
  112.     mulu    #80,d1    ;d1 = (LineNumber)*80
  113.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  114.  
  115. .plot2    addq.w    #1,d0
  116.     cmp.w    #SCRWIDTH,d0
  117.     bne.s    .loop3
  118.  
  119. ;==========================================================================;
  120. ;                                MAIN LOOP
  121. ;==========================================================================;
  122.  
  123. MainLoop:
  124.     move.l    SCRBase(pc),a6
  125.     CALL    scrWaitAVBL
  126.     move.l    Screen(pc),a0
  127.     CALL    scrSwapBuffers
  128.  
  129. ;==========================================================================;
  130. ;                             STAR ANIMATION
  131. ;==========================================================================;
  132.  
  133.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  134.     add.w    #XSPEED,d0               ;d0 = (StarXPos)+XSPEED
  135.     add.w    #YSPEED,d1               ;d1 = (StarYPos)+YSPEED
  136.     add.w    #ZSPEED,d2               ;d2 = (StarZPos)+ZSPEED
  137.     and.w    #%0000011111111111,d0
  138.     and.w    #%0000011111111111,d1
  139.     and.w    #%0000011111111111,d2
  140.     movem.w    d0/d1/d2,StarXPos
  141.  
  142.     lea    Sinus(pc),a0             ;a0 = Sinus table.
  143.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  144.     add.w    (a0,d0.w),d3
  145.     add.w    (a0,d1.w),d4
  146.     add.w    (a0,d2.w),d5
  147.     movem.w    d3/d4/d5,StarXAdd
  148.  
  149. ;===========================================================================;
  150. ;                              SCREEN CLEAR
  151. ;===========================================================================;
  152.  
  153.     move.l    BLTBase(pc),a6
  154.     move.l    Screen(pc),a1    ;a1 = GameScreen
  155.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  156.     move.l    GS_MemPtr3(a1),BMP_Data(a0)
  157.     CALL    bltClearBitmap
  158.  
  159. ;==========================================================================;
  160. ;                               DRAW STARS
  161. ;==========================================================================;
  162.  
  163.     lea    StarCoords,a0            ;Draw starfield
  164.     lea    PersTable,a1
  165.     lea    PlotXTable,a2
  166.     lea    PlotBTable,a3
  167.     lea    PlotYTable,a4
  168.     move.l    Screen(pc),a6
  169.     move.l    GS_MemPtr2(a6),a6
  170.  
  171.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  172.     add.w    #4096,d3                 ;d3 = ++4096
  173.     add.w    #4096,d4                 ;d4 = ++4096
  174.  
  175.     move.w    #NSTARS-1,d7
  176.  
  177. .draw1    movem.w    (a0)+,d0/d1/d2           ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  178.     add.w    d3,d0                    ;Increase XPos.
  179.     and.w    #8191,d0                 ;d0 = And'd
  180.     sub.w    #4096,d0                 ;d0 = --4096
  181.  
  182.     add.w    d4,d1                    ;Y-movement
  183.     and.w    #8191,d1                 ;d1 = And'd
  184.     sub.w    #4096,d1                 ;d1 = --4096
  185.  
  186.     add.w    d5,d2                    ;Z-movement
  187.     and.w    #8191,d2
  188.     add.w    d2,d2                    ;d2 = *2 [word]
  189.     move.w    (a1,d2.w),d6             ;d6 = Read from Perspective table.
  190.  
  191.     muls    d6,d0                    ;X-projection
  192.     swap    d0
  193.     add.w    #176,d0
  194.  
  195.     cmp.w    #SCRWIDTH-1,d0
  196.     bhi.s    .nodraw
  197.     muls    d6,d1                    ;Y-projection
  198.     swap    d1
  199.     add.w    #136,d1
  200.     cmp.w    #SCRHEIGHT-1,d1
  201.     bhi.s    .nodraw
  202.  
  203.     add.w    d0,d0                    ;d0 = *2 [word]
  204.     add.w    d1,d1                    ;d1 = *2 [word]
  205.     move.w    (a4,d1.w),d6             ;d6 = Plot Y.
  206.     add.w    (a2,d0.w),d6             ;d6 = ++PlotX.
  207.     move.w    (a3,d0.w),d0             ;d0 = BitValue.
  208.  
  209.     cmp.w    #7000,d2                 ;Now draw the star according to
  210.     bgt.s    .draw2                   ;its position in the Z axis.
  211.     bset    d0,(a6,d6.w)
  212.     dbra    d7,.draw1
  213.     bra.s    .done
  214.  
  215. .draw2    cmp.w    #13000,d2
  216.     bgt.s    .draw3
  217.     bset    d0,SCRWIDTH/8(a6,d6.w)
  218.     dbra    d7,.draw1
  219.     bra.s    .done
  220.  
  221. .draw3    bset    d0,(a6,d6.w)
  222.     bset    d0,SCRWIDTH/8(a6,d6.w)
  223. .nodraw    dbra    d7,.draw1
  224.  
  225. .done    move.l    DPKBase(pc),a6
  226.     move.l    JoyData(pc),a0
  227.     CALL    Query
  228.     move.l    JoyData(pc),a0
  229.     move.l    JD_Buttons(a0),d0
  230.     sub.l    a1,a1
  231.     moveq    #$00,d1
  232.     btst    #JB_LMB,d0
  233.     beq    MainLoop
  234.     rts
  235.  
  236. ;===========================================================================;
  237. ;                                  DATA
  238. ;===========================================================================;
  239.  
  240. JoyData:    dc.l  0
  241.  
  242. ScreenTags:    dc.l  TAGS_SCREEN
  243. Screen:        dc.l  0
  244.         dc.l  GSA_Palette,.palette
  245.         dc.l  GSA_Width,SCRWIDTH
  246.         dc.l  GSA_Height,SCRHEIGHT
  247.         dc.l  GSA_Attrib,TPLBUFFER
  248.         dc.l    GSA_BitmapTags,0
  249.         dc.l    BMA_Type,ILBM
  250.         dc.l    BMA_AmtColours,4
  251.         dc.l    TAGEND,0
  252.         dc.l  TAGEND
  253.  
  254. .palette    dc.l  PALETTE,4
  255.         dc.l  $000000,$D0D0D0,$606060,$202020
  256.  
  257. ;===========================================================================;
  258. ;                                STAR DATA
  259. ;===========================================================================;
  260.  
  261. StarXAdd:    dc.w  33                       ;Star stuff
  262. StarYAdd:    dc.w  12
  263. StarZAdd:    dc.w  -114
  264. StarXPos:    dc.w  0                        ;Sinus positions
  265. StarYPos:    dc.w  310
  266. StarZPos:    dc.w  1280
  267.  
  268.     INCLUDE    "GMSDev:source/asm/demos/StarSinus.i"
  269.  
  270.     SECTION    Storage,BSS
  271.  
  272. StarCoords:    ds.w  NSTARS*3    ;Star coordinates
  273. PersTable:    ds.w  8192    ;Perspective table
  274. PlotXTable:    ds.w  SCRWIDTH    ;Plot tables
  275. PlotBTable:    ds.w  SCRWIDTH
  276. PlotYTable:    ds.w  SCRHEIGHT
  277.  
  278. ;===========================================================================;
  279.  
  280. ProgName:    dc.b  "Stars 4",0
  281. ProgAuthor:    dc.b  "Paul Manias",0
  282. ProgDate:    dc.b  "10 December 1997",0
  283. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
  284. ProgShort:    dc.b  "4 colour star field demonstration.",0
  285.         even
  286.  
  287.